<!DOCTYPE html>
<html>
<head>
	<include file="Public:common-css" />
	<link type="text/css" rel="stylesheet" href="__ICSS__/orderpay.css" />
	<link href="__ICSS__/selectordie/selectordie_theme.css" rel="stylesheet">
	<link href="__ICSS__/validform/validform.css" rel="stylesheet">
	<script>window.history.forward();</script>
</head>
<body>
<div class="container">
<!-------------------------header--------------------------------->
<include file="Public:header" />
<!--------------------------content------------------------------->
    <div class="content">
   		<form action="__ROOT__/Order/createOrder" method="post" class="form">
    	<div class="order-affirm">
    		<div class="order-affirm-title"><strong>订单确认</strong></div>
    		<div class="order-affirm-content">
    			<dl class="member-address-box">
    				<dt><strong>配送地址</strong><a href="javascript:void(0)" id="add">添加新地址</a></dt>
    				<dd>
    					<ul>
    						<foreach item="addr" name="data.address">
    							<if condition="$addr.is_main eq 1">
    								<input type="hidden" value="<{$addr.id}>" name="addressId"/>
    							</if>
	    						<li <if condition="$addr.is_main eq 1">class="on"</if> ref="<{$addr.id}>" type="<{$addr.school_id}>">
	    							<div class="address-name"><{$addr.contact_name}></div>
	    							<div class="address-tel"><{$addr.contact_tel}></div>
	    							<div class="address-address" style="width: 550px;"><span style="max-width: 450px;"><{$addr.province}><{$addr.city}><{$addr.area}><notempty name="addr.school_id"><{$addr.schoolName}></notempty><{$addr.address}></span><if condition="$addr.is_main eq 1"><i>默认地址</i></if></div>
	    							<div class="address-icons"><i class="address-icon <empty name='addr.school_id'>address-exp-icon<else/>address-school-icon</empty>"></i></div>
	    							<div class="address-cog"><a href="javascript:void(0)"  onclick="edit(this)" ref="<{$addr.id}>">修改</a></div>
	    							<div class="select-icon"></div>
	    						</li>
    						</foreach>
    					</ul>
                    </dd>
    			</dl>
    			<dl class="delivery-time-box" >
    				<dt><strong>配送时间</strong></dt>
    				<dd>
    					<select class="myselect" id="deliveryDay" name="mailTime">
    						<foreach item="mt1" name="data.mailTimeList.today">
								<option value="<{$mt1}>" <if condition="$key eq 0">selected</if>><{$mt1}></option>
							</foreach>
							<foreach item="mt2" name="data.mailTimeList.tomorrow">
								<option value="<{$mt2}>"><{$mt2}></option>
							</foreach>
						</select>
                    </dd>
    			</dl>
    		</div>
    	</div>
    	<div class="wrap order-info">
	    	<input type="hidden" value="" class="prolist-param"/>
	    	<table width="100%" border="0" class="order-table">
		   		<thead>
		   			<tr>
						<td height="40" colspan="4" align="left" valign="middle"><span style="padding-left:25px; font-size:18px;">商品信息确认</span></td>
				  	</tr>
		   		</thead>
				<tbody>
					<foreach item="pro" name="data.productList">
					<tr ref=1 class="order-infomartion-box">
						<input type="hidden" name="goods[]" value="<{$pro.id}>_<{$pro.num}>"/>
						<td width="55%" height="60" align="left" valign="middle">
							<a href="__ROOT__/Product/details?productId=<{$pro.id}>" target="_blank">
							<img src="__IMGROOT__<{$pro.photo}>" width="45" height="45" style="float:left; margin:8px 16px 0 28px;"/>
							<span style="float:left; line-height:60px;"><{$pro.name}></span></a>
						</td>
					  	<td width="20%" height="60" align="center" valign="middle">¥<{$pro.price}></td>
					  	<td width="10%" height="60" align="center" valign="middle"><{$pro.num}></td>
						<td width="15%" height="60" align="center" valign="middle"><font class="org">¥<{$pro.totalPrice}></font></td>
					</tr>
					</foreach>
				</tbody>
			</table>
			<div class="order-total-box">
      			<p>商品总价：<font>¥<{$data.totalPrice}></font></p>
			</div>
			<div class="order-pay-box">
				<div class="other-price-box">
					<div class="remark-box"><span>添加备注：</span><input type="text" class="remark-input" placeholder="请输入您的备注" name="remark"/></div>
					<div class="price-content">
						<input type="hidden" id="mailSchoolStartFee" value="<{$data.mailSchoolStartFee}>"/>
						<input type="hidden" id="mailSchoolFee" value="<{$data.mailSchoolFee}>"/>
						<input type="hidden" id="mailCustomFee" value="<{$data.mailCustomFee}>"/>
						<input type="hidden" id="mailFreeFee" value="<{$data.mailFreeFee}>"/>
						<input type="hidden" id="totalPirce" value="<{$data.totalPrice}>"/>
						<span id="pay_type_school" style="display: none;">配送方式：校园模式，<{$data.mailSchoolStartFee}>元起送，配送费<{$data.mailSchoolFee}>元</span>
						<span id="pay_type_mail" style="display: none;">配送方式：快递模式，配送费<{$data.mailCustomFee}>元，<{$data.mailFreeFee}>起免配送费</span>
						<em>¥<font id="mail_fee">0.00</font></em>
					</div>
					<div class="total-price-box">
						<span>总计：<em>¥<font id="tpi">0.00</font></em></span>
					</div>
				</div>
				<input type="hidden" class="realPrice" value="<{$carInfo.totalPrice}>"/>
				
				<button class="order-pay-btn" id="pay-btn">立即支付</button>
				<div class="clearfix"></div>
			</div>
	    </div>
	    </form>
    </div>
    <div class="clr"></div>
<!--------------------------content-end--------------------------->
    <include file="Public:footer" />
</div>

</body>
<include file="Public:common-js" />
<script src="__IJS__/selectordie/selectordie.min.js"></script>
<script src="__IJS__/Validform_v5.3.2_min.js"></script>
<script type="text/javascript">
	$(function() {
		$('select').selectOrDie();
		
		$("#add").click(function() {
			layerDialog("新增地址",'__ROOT__/User/addAddress',"720px","530px",true);
		})
		
		$(".member-address-box ul li").bind("click",function(){
			$(".member-address-box ul li").each(function(){
				$(this).removeClass("on");
			})
			$(this).addClass("on");
			$("input[name='addressId']").val($(this).attr("ref"));
			//判断是否是快递模式
			if($(this).attr("type") == "0"){
				$("#pay_type_school").hide();
				$("#pay_type_mail").show();
				$(".delivery-time-box").hide();
				countPrice(0);
			}else{
				$("#pay_type_school").show();
				$("#pay_type_mail").hide();
				$(".delivery-time-box").show();
				countPrice(1);
			}
		})
		//初始化
		var type = $(".member-address-box ul li.on").attr("type");
		if(type == "0"){
			$("#pay_type_school").hide();
			$("#pay_type_mail").show();
			$(".delivery-time-box").hide();
			countPrice(0);
		}else{
			$("#pay_type_school").show();
			$("#pay_type_mail").hide();
			countPrice(1);
		}
		$("#pay-btn").click(function() {
			$(".form").submit();
			$(this).attr("disabled","disabled");
		})
		//提交表单
		var form = $(".form").Validform({
			tiptype:4,
			postonce:true,
			ajaxPost:true,
			callback:function(data){
				if(data.status == 1) {
					$.cookie("cart", null, { path: '/' });//删除购物车cookie
					layer.msg(data.info);
					window.location.href = "__ROOT__/Order/payment?orderCode=" + data.data;
				}else{
					layer.msg(data.info);
				}
			}
		});
	})
	//计算价格
	function countPrice(type){
		var totalPrice = 0;var mail_fee = 0;
		totalPrice = parseFloat($("#totalPirce").val());
		if(type == 0){//快递模式
			$("#pay-btn").removeClass().addClass('order-pay-btn');
			$("#pay-btn").html("立即支付");
			$("#pay-btn").attr("disabled",false);
			var mailCustomFee = parseFloat($("#mailCustomFee").val());
			var mailFreeFee = parseFloat($("#mailFreeFee").val());
			if(totalPrice < mailFreeFee){
				totalPrice = totalPrice + mailCustomFee;
				mail_fee = mailCustomFee;
			}
		}else{//校园模式
			var mailSchoolStartFee = parseFloat($("#mailSchoolStartFee").val());
			var mailSchoolFee = parseFloat($("#mailSchoolFee").val());
			if(totalPrice < mailSchoolStartFee){
				$("#pay-btn").removeClass().addClass('order-pay-btn-off');
				$("#pay-btn").html("还差" + (mailSchoolStartFee - totalPrice).toFixed(2) + "起送");
				$("#pay-btn").attr("disabled",true);
			}
			mail_fee = mailSchoolFee;
			totalPrice = totalPrice + mailSchoolFee;
		}
		$("#mail_fee").html(mail_fee.toFixed(2));
		$("#tpi").html(totalPrice.toFixed(2));
	}
	
	//修改
	function edit(t){
		layerDialog("修改地址",'__ROOT__/User/editAddress?id='+ $(t).attr("ref"),"720px","530px",true);
	}
</script>

</html>
